package com.tianzeculture.stagebao.activity.mine;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.bean.NoticeList;
import com.tianzeculture.stagebao.bean.OrderBean;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

import static com.tianzeculture.stagebao.net.base.AppBaseRestUsageV2.PICTURE_URL;

/**
 * Created by Administrator on 2018/8/17.
 */

public class NoticeAdapter extends RecyclerView.Adapter<NoticeAdapter.RecyclerViewHolder> {

    Context context;

    List<NoticeList> list;

    public NoticeAdapter(Context context, List<NoticeList> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_my_notice, parent, false);
        return new RecyclerViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerViewHolder holder, int position) {
        holder.setData(position);
    }


//

    @Override
    public int getItemCount() {
        return list.size();
    }

    class RecyclerViewHolder extends RecyclerView.ViewHolder {
        CircleImageView ivImageView;
        TextView tvButton;
        TextView tvName;
        TextView tvWorkType;
        TextView tvLocation;
        TextView tvMoney;
        TextView tvTime;
        RelativeLayout relativeLayout;

        public RecyclerViewHolder(View itemView) {
            super(itemView);
            ivImageView = itemView.findViewById(R.id.iv_header);
            tvButton = itemView.findViewById(R.id.tv_button);
            tvName = itemView.findViewById(R.id.tv_name);
            tvWorkType = itemView.findViewById(R.id.tv_work_type);
            tvLocation = itemView.findViewById(R.id.tv_location);
            tvMoney = itemView.findViewById(R.id.tv_money);
            tvTime = itemView.findViewById(R.id.tv_time);
            relativeLayout = itemView.findViewById(R.id.relativeLayout);
        }

        public void setData(final int position) {
            final NoticeList orderBean = list.get(position);
            Glide.with(context).load(PICTURE_URL + orderBean.getImgurl()).error(R.mipmap.icon_head).placeholder(R.mipmap.icon_head).into(ivImageView);
            tvName.setText(orderBean.getTitle());
            tvWorkType.setText(orderBean.getWorkType());
            tvLocation.setText(orderBean.getAddress());
            tvMoney.setText("￥ " + orderBean.getUnitPrice());
            tvTime.setText("投递时间: " + orderBean.getOrderTime().substring(0, 10));
            tvButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    orderLisener.contact(position, orderBean);
                }
            });
            relativeLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    orderLisener.toDetaile(position, orderBean);
                }
            });
        }
    }

    public void setOrderLisener(OrderLisener lisener) {
        orderLisener = lisener;
    }

    OrderLisener orderLisener;

    public interface OrderLisener {
        void contact(int position, NoticeList bean);

        void toDetaile(int position, NoticeList bean);
    }
}
